﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using HashMaster.Lib;

namespace HashMaster.Service
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
    // a single instance of the service to process all calls.	
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class TaskService
    {

        /// <summary>
        /// 获取所有任务
        /// </summary>
        /// <param name="clientName"></param>
        /// <param name="macAddress"></param>
        /// <returns></returns>
        [WebGet(UriTemplate = "?Mode={mode}")]
        public List<Task> Get( string mode)
        {
            switch (mode)
            {
                /// 只获取未完成任务
                case"1":
                    return Utility.GetAvailableTasts();
                    
                /// 只获取为导出的任务
                case "2":
                    return Utility.GetExtractableTasks();
                    
                case "3":
                    return Utility.GetHiddenTasks();
                default:
                    //break;
                    return new List<Task>();
                 
            }

            

        }


        /// <summary>
        /// 新增一个任务
        /// </summary>
        /// <param name="clientName"></param>
        /// <param name="macAddress"></param>
        /// <returns>没有返回值</returns>
        [WebInvoke(UriTemplate = "{imei}/{sha}/{sliceWidth}", Method = "POST")]
        public bool AddNewTask(string imei,string sha,string sliceWidth)
        {
            Task task = new Task { Imei = imei, Sha = sha, SliceWidth = int.Parse(sliceWidth) };
            //{imei}/{sha}/{sliceWidth}
            //string imei, string sha,string sliceWidth
            return Utility.AddNewTask(task);
        }

        [WebInvoke(UriTemplate = "{imei}/{priority}/{memo}/{extracted}", Method = "PUT")]
        public bool ModifyTask(string imei, string priority, string memo, string extracted)
        {
            return Utility.ModifyTask(imei, int.Parse(priority), memo, bool.Parse(extracted));
        }

        //[WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
        //public void Delete(string id)
        //{
        //    // TODO: Remove the instance of SampleItem with the given id from the collection
        //    throw new NotImplementedException();
        //}

    }
}
